#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

//VS2015

class Solution 
{
public:
	vector<int> twoSum(vector<int>& nums, int target)
	{
		vector<int> result;
		multimap<int, int> mVal;

		int other;

		for (size_t i = 0;i < nums.size();++i)
		{
			mVal.insert(make_pair(nums[i], i + 1));
		}

		int findCount;

		for (auto itor = mVal.begin();itor != mVal.end();++itor)
		{
			other = target - itor->first;
			findCount = mVal.count(other);

			if (findCount == 0)
			{
				continue;
			}
			else if (findCount == 1)
			{
				result.push_back(itor->second);
				result.push_back(mVal.find(other)->second);
				sort(result.begin(), result.end());
				return result;
			}
			else if (findCount > 1)
			{
				result.push_back(itor->second);
				auto findItor = mVal.find(other);

				for (int i = 0;i < findCount;++i,++findItor)
				{
					if (itor->second != findItor->second)
					{
						result.push_back(findItor->second);
						break;
					}
				}
				sort(result.begin(), result.end());
				return result;
			}
		}
		return vector<int>();
	}

};

int main()
{
	Solution a;
	vector<int> b;
	b.push_back(2);
	b.push_back(7);
	b.push_back(0);
	b.push_back(0);
	auto c=a.twoSum(b, 0);

	return 0;
}